home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / ioport / iotest4.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-02-15  |  14.2 KB  |  408 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   4116
  5.    ClientLeft      =   1644
  6.    ClientTop       =   7236
  7.    ClientWidth     =   5772
  8.    Height          =   4500
  9.    Left            =   1596
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4116
  12.    ScaleWidth      =   5772
  13.    Top             =   6900
  14.    Width           =   5868
  15.    Begin VB.TextBox txtaddress 
  16.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  17.          Name            =   "Arial Black"
  18.          Size            =   12
  19.          Charset         =   0
  20.          Weight          =   400
  21.          Underline       =   0   'False
  22.          Italic          =   0   'False
  23.          Strikethrough   =   0   'False
  24.       EndProperty
  25.       Height          =   456
  26.       Left            =   360
  27.       TabIndex        =   9
  28.       Top             =   3360
  29.       Width           =   1572
  30.    End
  31.    Begin VB.TextBox txtbitsize 
  32.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  33.          Name            =   "Arial Black"
  34.          Size            =   12
  35.          Charset         =   0
  36.          Weight          =   400
  37.          Underline       =   0   'False
  38.          Italic          =   0   'False
  39.          Strikethrough   =   0   'False
  40.       EndProperty
  41.       Height          =   456
  42.       Left            =   360
  43.       TabIndex        =   8
  44.       Top             =   2640
  45.       Width           =   1572
  46.    End
  47.    Begin VB.CommandButton cmdexit 
  48.       Caption         =   "E&xit"
  49.       Height          =   372
  50.       Left            =   2400
  51.       TabIndex        =   7
  52.       Top             =   3360
  53.       Width           =   732
  54.    End
  55.    Begin VB.CommandButton cmdbitsize 
  56.       Caption         =   "&Toggle Bit size"
  57.       Height          =   372
  58.       Left            =   2160
  59.       TabIndex        =   6
  60.       Top             =   2640
  61.       Width           =   1332
  62.    End
  63.    Begin VB.CommandButton cmdread 
  64.       Caption         =   "&Read from port"
  65.       Height          =   372
  66.       Left            =   2160
  67.       TabIndex        =   5
  68.       Top             =   1920
  69.       Width           =   1332
  70.    End
  71.    Begin VB.TextBox txtusread 
  72.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  73.          Name            =   "Arial Black"
  74.          Size            =   12
  75.          Charset         =   0
  76.          Weight          =   400
  77.          Underline       =   0   'False
  78.          Italic          =   0   'False
  79.          Strikethrough   =   0   'False
  80.       EndProperty
  81.       Height          =   456
  82.       Left            =   3720
  83.       TabIndex        =   4
  84.       Top             =   1920
  85.       Width           =   1692
  86.    End
  87.    Begin VB.TextBox txtvalue 
  88.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  89.          Name            =   "Arial Black"
  90.          Size            =   12
  91.          Charset         =   0
  92.          Weight          =   400
  93.          Underline       =   0   'False
  94.          Italic          =   0   'False
  95.          Strikethrough   =   0   'False
  96.       EndProperty
  97.       Height          =   456
  98.       Left            =   360
  99.       TabIndex        =   3
  100.       Top             =   1920
  101.       Width           =   1572
  102.    End
  103.    Begin VB.TextBox txtuswrite 
  104.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  105.          Name            =   "Arial Black"
  106.          Size            =   12
  107.          Charset         =   0
  108.          Weight          =   400
  109.          Underline       =   0   'False
  110.          Italic          =   0   'False
  111.          Strikethrough   =   0   'False
  112.       EndProperty
  113.       Height          =   456
  114.       Left            =   3720
  115.       TabIndex        =   2
  116.       Top             =   1200
  117.       Width           =   1692
  118.    End
  119.    Begin VB.TextBox txtwrite 
  120.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  121.          Name            =   "Arial Black"
  122.          Size            =   12
  123.          Charset         =   0
  124.          Weight          =   400
  125.          Underline       =   0   'False
  126.          Italic          =   0   'False
  127.          Strikethrough   =   0   'False
  128.       EndProperty
  129.       Height          =   456
  130.       Left            =   360
  131.       TabIndex        =   1
  132.       Top             =   1200
  133.       Width           =   1572
  134.    End
  135.    Begin VB.CommandButton cmdwrite 
  136.       Caption         =   "&Write to port"
  137.       Height          =   372
  138.       Left            =   2160
  139.       TabIndex        =   0
  140.       Top             =   1200
  141.       Width           =   1332
  142.    End
  143.    Begin VB.Label lblwrite 
  144.       Caption         =   "Value to Write"
  145.       Height          =   252
  146.       Left            =   360
  147.       TabIndex        =   17
  148.       Top             =   960
  149.       Width           =   1572
  150.    End
  151.    Begin VB.Label lblread 
  152.       Caption         =   "Value Read"
  153.       Height          =   252
  154.       Left            =   360
  155.       TabIndex        =   16
  156.       Top             =   1680
  157.       Width           =   1572
  158.    End
  159.    Begin VB.Label lblbitsize 
  160.       Caption         =   "Size in Bits"
  161.       Height          =   252
  162.       Left            =   360
  163.       TabIndex        =   15
  164.       Top             =   2400
  165.       Width           =   972
  166.    End
  167.    Begin VB.Label lbladdress 
  168.       Caption         =   "I/O Port Address"
  169.       Height          =   252
  170.       Left            =   360
  171.       TabIndex        =   14
  172.       Top             =   3120
  173.       Width           =   1452
  174.    End
  175.    Begin VB.Label lblusread 
  176.       Height          =   252
  177.       Left            =   3720
  178.       TabIndex        =   13
  179.       Top             =   1680
  180.       Width           =   1812
  181.    End
  182.    Begin VB.Label lbluswrite 
  183.       Height          =   252
  184.       Left            =   3720
  185.       TabIndex        =   12
  186.       Top             =   960
  187.       Width           =   1692
  188.    End
  189.    Begin IOPORTLib.Ioport Ioport1 
  190.       Left            =   4080
  191.       Top             =   2880
  192.       _Version        =   65536
  193.       _ExtentX        =   1503
  194.       _ExtentY        =   1503
  195.       _StockProps     =   0
  196.    End
  197.    Begin VB.Label Label2 
  198.       Caption         =   "(For Visual Basic 4.0 Using IOPORT OCX)"
  199.       Height          =   252
  200.       Left            =   1320
  201.       TabIndex        =   11
  202.       Top             =   600
  203.       Width           =   3132
  204.    End
  205.    Begin VB.Label Label1 
  206.       BackColor       =   &H00C0C0C0&
  207.       Caption         =   "IOPORT Test Program"
  208.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  209.          Name            =   "Arial"
  210.          Size            =   19.8
  211.          Charset         =   0
  212.          Weight          =   400
  213.          Underline       =   0   'False
  214.          Italic          =   0   'False
  215.          Strikethrough   =   0   'False
  216.       EndProperty
  217.       ForeColor       =   &H00FF0000&
  218.       Height          =   492
  219.       Left            =   840
  220.       TabIndex        =   10
  221.       Top             =   120
  222.       Width           =   4212
  223.    End
  224. Attribute VB_Name = "Form1"
  225. Attribute VB_Creatable = False
  226. Attribute VB_Exposed = False
  227. 'if the "toggle Bit Size" button is clicked
  228. Private Sub cmdbitsize_Click()
  229. 'then if the IOPORT.bitsize property is currently the value 8
  230. 'change it to 16 and change the labels above the "write" and "read"
  231. 'textboxes to reflect signed and unsigned 16-bit values are being
  232. 'displayed
  233.  If Val(txtbitsize.Text) = 8 Then
  234.     txtbitsize.Text = 16
  235.     Ioport1.bitsize = 16
  236.     lbluswrite.Caption = "Unsigned value Write"
  237.     lblusread.Caption = "Unsigned value Read"
  238.     lblwrite.Caption = "Signed value Write"
  239.     lblread.Caption = "Signed value Read"
  240. 'but if the IOPORT.bitsize property is currently the value 16
  241. 'then change it to 8 and change the labels above the "write" and "read"
  242. 'textboxes to reflect only 8-bit values are being displayed
  243.     txtbitsize.Text = 8
  244.     Ioport1.bitsize = 8
  245.     lbluswrite.Caption = ""
  246.     lblusread.Caption = ""
  247.     lblwrite.Caption = "Value to Write"
  248.     lblread.Caption = "Value Read"
  249. End If
  250. 'now clear all read and write text boxes
  251. txtwrite.Text = ""
  252. txtvalue.Text = ""
  253. txtuswrite.Text = ""
  254. txtusread.Text = ""
  255. End Sub
  256. 'if the "Exit" button is clicked then end the program
  257. Private Sub cmdexit_Click()
  258. End Sub
  259. 'if the "Read from Port" button is clicked
  260. Private Sub cmdread_Click()
  261. 'then if the IOPORT.bitsize value is 8
  262. 'read the value of IOPORT.value to the "Value read" text box and
  263. 'ensure that the "Unsigned value Read" textbox is blank.
  264.   If Val(Ioport1.bitsize) = 8 Then
  265.     txtvalue.Text = Ioport1.Value
  266.     txtusread.Text = ""
  267. 'but if the IOPORT.bitsize value is 16
  268. 'then read the value of IOPORT.value and display it in the "Value read"
  269. 'textbox and read the value of IOPORT.USValue and display it in the
  270. '"Unsigned value Read" textbox
  271.     Else
  272.     txtvalue.Text = Ioport1.Value
  273.     txtusread.Text = Ioport1.USValue
  274.     End If
  275.    End Sub
  276. 'if the "Write to Port" button is clicked
  277. Private Sub cmdwrite_Click()
  278. 'then if the IOPORT.bitzise value is 8 then send the value of the
  279. '"Value to Write" text box to the port and ensure that the "Unsigned
  280. 'value to Write" text box is blank
  281.     If Val(Ioport1.bitsize) = 8 Then
  282.     Ioport1.Value = Val(txtwrite.Text)
  283.     txtuswrite.Text = ""
  284. 'but if the IOPORT.bitsize value is 16 then there are two posibilities:
  285. 'either the user wishes to write a signed 16-bit value, or the user wishes
  286. 'to write an unsigned 16-bit value, the text boxes must be checked to find
  287. 'out which 16-bit format to write
  288.     Else
  289.     'first check to see if there is data in the "Unsigned value to Write"
  290.     'text box, if so this is the format that will be written to the
  291.     'IOPORT.USValue and the "Signed value to Write" text box will be blanked
  292.         If (txtuswrite.Text <> "") Then
  293.         Ioport1.USValue = Val(txtuswrite.Text)
  294.         txtwrite.Text = ""
  295.     'otherwise the data in the "Signed value to Write" will be written to the
  296.     'IOPORT.USValue and the "Unsigned value to Write" will be blanked
  297.         Else
  298.         Ioport1.USValue = Val(txtwrite.Text)
  299.         txtuswrite.Text = ""
  300.         End If
  301.         
  302.     End If
  303. End Sub
  304. 'When the IOTEST application is first loaded...
  305. Private Sub Form_Load()
  306. 'then set these variables to these values....
  307.     address = 888
  308.     bitsize = 8
  309.     Value = 0
  310.  'and display these values in the appropriate text boxes...
  311.     txtaddress = address
  312.     txtbitsize = bitsize
  313.     txtvalue = Value
  314. End Sub
  315. 'When a user clicks on the "I/O Port Address" text box...
  316. Private Sub txtaddress_Click()
  317. 'clear it out to receive a new address value from the user
  318.     txtaddress.Text = ""
  319. End Sub
  320. 'When a user enters a number in the "I/O Port Address" text box
  321. 'and then hits ENTER, (ENTER causes the variable: "KeyAscii" to be equal to 13)
  322. Private Sub txtaddress_KeyPress(KeyAscii As Integer)
  323.     If KeyAscii = 13 Then
  324.         'as long as the value entered is between 0 and 65535..
  325.         If Val(txtaddress.Text >= 0) And Val(txtaddress.Text <= 65535) Then
  326.         
  327.         'then set the IOPORT.address to this new value
  328.         Ioport1.address = Val(txtaddress.Text)
  329.         
  330.         'otherwise the value entered is out of range, send an error message
  331.         'to the user.
  332.         Else
  333.         MsgBox "I/O Address must be between 0 and 65535!", vbExclamation, "Address Value ERROR"
  334.         
  335.         End If
  336.     End If
  337. End Sub
  338. 'When the user clicks on the "Unsigned value to Write" text box...
  339. Private Sub txtuswrite_Click()
  340.     'clear it out to receive a new unsigned write value from the user
  341.     txtuswrite.Text = ""
  342. End Sub
  343. 'When a user enters a number in the "Unsigned value to Write" text box
  344. 'and then hits ENTER, (ENTER causes the variable: "KeyAscii" to be equal to 13)
  345. Private Sub txtuswrite_KeyPress(KeyAscii As Integer)
  346.     If KeyAscii = 13 Then
  347.     'as long as the value is between 0 and 65535...
  348.         If (Val(txtuswrite.Text) >= 0) And (Val(txtuswrite.Text) <= 65535) Then
  349.         
  350.         'set the IOPORT.USValue to this number
  351.         Ioport1.USValue = Val(txtuswrite.Text)
  352.         
  353.         'otherwise the wrong value was entered, send an error message to the user
  354.         Else
  355.         MsgBox "Unsigned Write value must be between 0 and 65535!", vbExclamation, "Unsigned Write Value ERROR"
  356.         
  357.         'clear out the "Unsigned value to Write" text box..
  358.         txtuswrite.Text = ""
  359.         End If
  360.     End If
  361. End Sub
  362. 'when a user clicks on the "Value to Write" or "Signed value to Write" text box
  363. '(which is the same box, its title depends on 8-bit or 16-bit mode as shown
  364. 'in "Size in Bits" text box)
  365. Private Sub txtwrite_Click()
  366.     'clear it out to receive a new write value from the user
  367.     txtwrite.Text = ""
  368. End Sub
  369. 'When a user enters a number in the "Value to Write" text box
  370. 'and then hits ENTER, (ENTER causes the variable: "KeyAscii" to be equal to 13)
  371. Private Sub txtwrite_KeyPress(KeyAscii As Integer)
  372.     If KeyAscii = 13 Then
  373.     'check to see if IOPORT1.Bitsize is 16
  374.         If Val(Ioport1.bitsize) = 16 Then
  375.         'if bitsize is 16 we must only allow values between -32767 and +32768
  376.          If (Val(txtwrite.Text) >= -32767) And (Val(txtwrite.Text) <= 32768) Then
  377.         
  378.         'set the IOPORT.USValue to this number
  379.         Ioport1.Value = Val(txtwrite.Text)
  380.         
  381.         'otherwise the wrong value was entered, send an error message to the user
  382.         Else
  383.         MsgBox "Signed Write value must be between -32767 and 32678!", vbExclamation, "Signed Write Value ERROR"
  384.         
  385.         'clear out the "Signed value to Write" text box...
  386.         txtwrite.Text = ""
  387.         End If
  388.         
  389.     'if instead, IOPORT1.bitsize is 8..
  390.     Else
  391.     'as long as the value entered is between 0 and 255...
  392.         If (Val(txtwrite.Text) >= 0) And (Val(txtwrite.Text) <= 255) Then
  393.         
  394.         'set the IOPORT.value to this number
  395.         Ioport1.Value = Val(txtwrite.Text)
  396.         
  397.         'otherwise the wrong value was entered, send an error message to the user
  398.         Else
  399.         MsgBox "Write value must be between 0 and 255!", vbExclamation, "Write Value ERROR"
  400.         
  401.         'clear out the "Value to Write" text box..
  402.         txtwrite.Text = ""
  403.         End If
  404.         
  405.     End If
  406. End If
  407. End Sub
  408.